// 客户资料
<template>
  <div class="customer">
    <el-container>
      <el-main>
        <div ref="borrow">
          <el-row class="bgc">
            <el-col :span="24"> 担保信息</el-col>
          </el-row>
          <el-form :label-position="labelPosition" label-width="100px" :model="loanInfo" :inline="true">
            <!-- <el-form-item label="担保性质">
              <el-select v-model="loanInfo.region" placeholder="请选择">
                <el-option label="个人" value="个人" />
                <el-option label="对公" value="对公" />
              </el-select>
            </el-form-item> -->
            <el-form-item label="担保产品">
              <el-input v-model="loanInfo.loan_name" disabled />
            </el-form-item>
            <el-form-item label="还款方式">
              <el-input v-model="loanInfo.method" disabled />
            </el-form-item>
            <el-form-item label="申请金额">
              <el-input v-model="loanInfo.apply_quota" disabled>
                <template #append>
                  <span> 元</span>
                </template>
              </el-input>
            </el-form-item>
            <el-form-item label="综合利率">
              <el-input v-model="loanInfo.approval_rate" disabled>
                <template #append>
                  <span> %</span>
                </template>
              </el-input>
            </el-form-item>
            <el-form-item label="担保类型">
              <el-input v-model="loanInfo.loan_type" disabled />
            </el-form-item>
            <el-form-item label="担保用途">
              <el-input v-model="loanInfo.purpose_name" disabled />
            </el-form-item>
            <el-form-item label="担保期限">
              <el-input v-model="loanInfo.loan_stages" disabled>
                <template #append>
                  <span> 个月</span>
                </template>
              </el-input>
            </el-form-item>
            <el-form-item label="审批金额">
              <el-input v-model="loanInfo.approval_amount" disabled>
                <template #append>
                  <span> 元</span>
                </template>
              </el-input>
            </el-form-item>
            <el-form-item label="担保管理费">
              <el-input v-model="loanInfo.manage_amt" disabled>
                <template #append>
                  <span> 元</span>
                </template>
              </el-input>
            </el-form-item>
          </el-form>
        </div>

        <div>
          <div v-for="(item, index) in state.lists" :key="index">
            <el-row class="bgc">
              <el-col :span="24">{{ item.name }}</el-col>
            </el-row>
            <el-form :label-position="labelPosition" label-width="100px" :model="formLabelAlign" :inline="true" class="demo-form-inline">
              <el-form-item :label="val.name" v-for="(val, i) in item.list" :key="i">
                <el-input v-model="val.value" disabled />
              </el-form-item>
            </el-form>
          </div>
        </div>

        <div ref="identity">
          <el-row class="bgc">
            <el-col :span="24">身份认证信息</el-col>
          </el-row>
          <el-form :label-position="labelPosition" label-width="100px" :model="formLabelAlign" :inline="true">
            <el-form-item label="身份证正/反面">
              <el-image style="width: 100px; height: 100px" :src="frontUrl" :zoom-rate="1.2" :preview-src-list="frontList" :initial-index="0" fit="cover" />
            </el-form-item>
            <el-form-item label="手持身份证" style="max-width: 460px">
              <el-image style="width: 100px; height: 100px" :src="versoUrl" :zoom-rate="1.2" :preview-src-list="versoList" :initial-index="0" fit="cover" />
            </el-form-item>
          </el-form>
        </div>

        <div ref="face">
          <el-row class="bgc">
            <el-col :span="24">人脸识别</el-col>
          </el-row>
          <el-form :label-position="labelPosition" label-width="100px" :model="formLabelAlign" :inline="true">
            <el-form-item label="认证状态">
              <el-input v-model="formLabelAlign.authentication" disabled />
            </el-form-item>
          </el-form>
        </div>

        <!-- <div ref="bank">
          <el-row class="bgc">
            <el-col :span="24">银行信息</el-col>
          </el-row>
          <el-form :label-position="labelPosition" label-width="100px" :model="formLabelAlign" :inline="true">
            <el-form-item label="开户行">
              <el-input v-model="formLabelAlign.openBank" disabled />
            </el-form-item>
            <el-form-item label="开户地">
              <el-input v-model="formLabelAlign.openAddr" disabled />
            </el-form-item>
            <el-form-item label="银行账号">
              <el-input v-model="formLabelAlign.cardNo" disabled />
            </el-form-item>
            <el-form-item label="户名">
              <el-input v-model="formLabelAlign.userName" disabled />
            </el-form-item>
            <el-form-item label="支行名称">
              <el-input v-model="formLabelAlign.branchName" disabled />
            </el-form-item>
          </el-form>
        </div> -->

        <div ref="car">
          <el-row class="bgc">
            <el-col :span="24">车辆证明材料</el-col>
          </el-row>
          <el-col :span="11">
            <el-form :label-position="labelPosition" label-width="100px" :model="formLabelAlign" :inline="true">
              <el-form-item>
                <el-tooltip class="box-item" effect="dark" content="行车证" placement="top-start">
                  <el-button>行车证</el-button>
                </el-tooltip>
              </el-form-item>
            </el-form>
          </el-col>
        </div>

        <div ref="trial">
          <el-row class="bgc">
            <el-col :span="24">客户信息与材料核查-初审</el-col>
          </el-row>
          <el-form :label-position="labelPosition" label-width="100px" :model="formLabelAlign" :inline="true">
            <el-form-item label="初审结果" v-if="route.query.status != 1">
              <el-input v-model="formLabelAlign.firstResult" disabled />
            </el-form-item>
            <el-form-item label="初审结果" v-else>
              <el-select v-model="formLabelAlign.firstResult" placeholder="请选择">
                <el-option label="通过" value="1" />
                <el-option label="驳回" value="2" />
                <el-option label="拒绝" value="3" />
              </el-select>
            </el-form-item>
            <el-form-item label="审核意见">
              <el-input v-model="formLabelAlign.firstOpinion" type="textarea" :disabled="route.query.status != 1" />
            </el-form-item>
            <!-- <el-form-item label="审核日期">
              <div>{{ firstTime }}</div>
            </el-form-item> -->
            <div v-show="route.query.status == 1">
              <el-form-item v-if="route.query.status == 1" class="mg-30">
                <el-button type="info">提交审核</el-button>
              </el-form-item>
            </div>
          </el-form>
        </div>
      </el-main>
      <el-aside width="200px">
        <div class="customer-right">
          <div v-for="(item, index) in refList" :key="index" @click="handle(item, index)" :class="[activeId == index ? 'active' : 'box1']">
            {{ item.text }}
          </div>
        </div>
      </el-aside>
    </el-container>
  </div>
</template>
<script setup>
import { onMounted, reactive, ref } from "vue";
import { loanFinalAudit, handleLoanFirstAudit, loanReexamine, getImage, queryListInfo, getLoanFinalAudit, loanReexamineInfo, loanFirstAudit, getPhoto, getInfo } from "@/api/loanBefore";
import { getId } from "@/utils/auth";
import { bankCardDetail } from "@/api/afterLoan/index";
import { ElMessageBox, ElMessage, ElLoading } from "element-plus";
import { loanTypes, methodType } from "@/utils/dict";
import { useRouter } from "vue-router";
const router = useRouter();
const route = useRoute();
const labelPosition = ref("right");
const borrow = ref(null);
const person = ref(null);
const address = ref(null);
const linkman = ref(null);
const job = ref(null);
const identity = ref(null);
const face = ref(null);
const bank = ref(null);
const car = ref(null);
const activeId = ref(null);
const trial = ref(null);
const fullscreenLoading = ref(false);
const frontUrl = ref(null); //正面
const frontList = ref([]); //正面预览
const versoUrl = ref(null); //反面
const versoList = ref([]); //反面预览

const state = reactive({
  loanInfo: {}, //担保信息
  formLabelAlign: {
    // finalRate: route.query.approval_rate ? route.query.approval_rate : "", //终审利率
    finalResult: "", //终审结果
    finalOpinion: "", //终审意见
    finalLimit: "", //终审额度批复
    firstResult: "", //初审结果
    firstOpinion: "", //初审意见
    recheckResult: "", //复审结果
    recheckOpinion: "", //复审意见
    // recheckLimit: route.query.apply_quota ? route.query.apply_quota : "", //复审额度批复
    // recheckRate: route.query.approval_rate ? route.query.approval_rate : "", //复审利率
    authentication: "", //人脸认证
    type: "",
    openBank: "", //开户行
    openAddr: "", //开户地
    cardNo: "", //银行账号
    userName: "", //户名
    branchName: "", //支行名称
  },
  lists: [], //展示菜单项
});

const { formLabelAlign, loanInfo } = toRefs(state);

onMounted(() => {
  // firstTime.value = route.query.first_audit_time ? route.query.first_audit_time : "";
  // recheckTime.value = route.query.reexamine_time ? route.query.reexamine_time : "";
  loanInfo.value = { ...route.query };
  loanInfo.value.loan_type = loanTypes(loanInfo.value.loan_type);
  loanInfo.value.method = methodType(loanInfo.value.method);
  getList();
  queryPhoto();
});

const url = "https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg";
const srcList = [
  "https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg",
  "https://fuss10.elemecdn.com/1/34/19aa98b1fcb2781c4fba33d850549jpeg.jpeg",
  "https://fuss10.elemecdn.com/0/6f/e35ff375812e6b0020b6b4e8f9583jpeg.jpeg",
  "https://fuss10.elemecdn.com/9/bb/e27858e973f5d7d3904835f46abbdjpeg.jpeg",
  "https://fuss10.elemecdn.com/d/e6/c4d93a3805b3ce3f323f7974e6f78jpeg.jpeg",
  "https://fuss10.elemecdn.com/3/28/bbf893f792f03a54408b3b7a7ebf0jpeg.jpeg",
  "https://fuss10.elemecdn.com/2/11/6535bcfb26e4c79b48ddde44f4b6fjpeg.jpeg",
];
const refList = reactive([
  { name: borrow, text: "担保信息" },
  // { name: person, text: "个人信息" },
  // { name: address, text: "居住信息" },
  // { name: linkman, text: "联系人信息" },
  // { name: job, text: "职业信息" },
  // { name: identity, text: "身份认证信息" },
  // { name: face, text: "人脸识别" },
  // { name: bank, text: "银行信息" },
  // { name: car, text: "车辆证明材料" },
  { name: trial, text: "审批" },
]);

//获取身份证照片
function queryPhoto() {
  getPhoto(route.query.user_id).then((res) => {
    if (res.code == 200) {
      getImage({
        file_name: "",
        file_path: `${res.data.positive},${res.data.otherSide}`,
      }).then((result) => {
        if (result.code == 200) {
          frontUrl.value = "http://" + result.data[0].http_url;
          versoUrl.value = "http://" + result.data[1].http_url;
          frontList.value.push(frontUrl.value);
          versoList.value.push(versoUrl.value);
        } else {
          return ElMessage({
            message: res.msg,
            type: "warning",
          });
        }
      });
    } else {
      return ElMessage({
        message: res.msg,
        type: "warning",
      });
    }
  });
  getInfo(route.query.user_id).then((res) => {
    if (res.code == 200) {
      formLabelAlign.value.authentication = res.data.faceStatus == 0 ? "认证失败" : "认证通过";
    } else {
      return ElMessage({
        message: res.msg,
        type: "warning",
      });
    }
  });
}

function handle(item, index) {
  activeId.value = index;
  console.log(index, "878787");
  item.name.scrollIntoView();
}

//查询银行卡信息
function getCardInfo() {
  bankCardDetail(route.query.debit_card_id).then((res) => {
    console.log(res, "sssssssssss", "银行卡信息");
    if (res.code == 200) {
      formLabelAlign.value.openBank = res.data.bankName;
      formLabelAlign.value.openAddr = res.data.openingBranch;
      formLabelAlign.value.cardNo = res.data.cardNo;
      // formLabelAlign.value.userName=res.data.bankName
    } else {
      return ElMessage({
        message: res.msg,
        type: "warning",
      });
    }
  });
}

//查询列表数据
function getList() {
  queryListInfo(route.query.user_id, route.query.loan_id).then((res) => {
    console.log(res, "resresres");
    if (res.code == 200) {
      if (res.data.length > 0) {
        // res.data.forEach((item) => {});
        state.lists = res.data;
        if (route.query.status != 1) {
          firstLookover();
        }
      }
    } else {
      return ElMessage({
        message: res.msg,
        type: "warning",
      });
    }
  });
}

//查询初审详情
function firstLookover() {
  console.log(111111, "初审详情");
  loanFirstAudit(route.query.id).then((res) => {
    console.log(res, "初审详情");
    if (res.code == 200) {
      if (res.data.length > 0) {
        switch (res.data[0].status) {
          case 1:
            formLabelAlign.value.firstResult = "通过";
            formLabelAlign.value.firstOpinion = res.data[0].details;
            break;
          case 2:
            formLabelAlign.value.firstResult = "驳回";
            formLabelAlign.value.firstOpinion = res.data[0].details;
            break;
          case 3:
            formLabelAlign.value.firstResult = "拒绝";
            formLabelAlign.value.firstOpinion = res.data[0].details;
            break;
        }
      }
    } else {
      return ElMessage({
        message: res.msg,
        type: "warning",
      });
    }
  });
}
</script>
<style lang="scss" scoped>
.customer {
  overflow: auto;
}
.bgc {
  background: #f2f2f2;
  margin-bottom: 5px;
  height: 30px;
  line-height: 30px;
  font-size: 16px;
}
.box1 {
  text-align: center;
  color: #999;
  border-bottom: 1.5px solid #e4e4e4;
  &:hover {
    cursor: pointer;
    color: #000;
  }
}
.mg-30 {
  margin-left: 100px;
}

:deep(.el-aside) {
  margin-top: 5px;
  background: #fff;
}
:deep(.el-main) {
  padding: 0;
  // flex: 80%;
}
.active {
  text-align: center;
  color: #000;
  border-bottom: 2px solid #000;
}
.personStyle {
  margin-right: 20px;
}
:deep(.el-form-item--default) {
  margin-bottom: 5px;
  width: 40%;
}
:deep(.el-select) {
  width: 100%;
}
:deep(.el-form-item) {
  margin-right: 120px;
}
.customer-right {
  position: fixed;
  border: 1px solid #e4e4e4;
  padding: 20px;
}

.item-mg {
  margin-top: 38px;
}
</style>
